<script type="text/javascript">
	RED.nodes.registerType('hmac', {
		category: 'function',
		color: '#a6bbcf',
		defaults: {
            name: {value: ''}, 
            algorithm: {value: 'HmacMD5', required: true},  
            key: {value: '', required: true},
            fieldTypeToHash: {value: "msg"},
		},
		inputs: 1,
		outputs: 1,
		icon: "hash.png",
		label: function () {
			return this.name || "hmac";
        }, 
        oneditprepare: function() {
            if (!this.fieldTypeToHash) {
                this.fieldTypeToHash = 'msg';
            }
            $("#node-input-key").typedInput({
                default: 'msg',
                types: ['msg'],
                typeField: $("#node-input-fieldTypeToHash")
            }); 
        }
	});
</script>

<script type="text/x-red" data-template-name="hmac">
    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i>节点名称</label>
        <input type="text" id="node-input-name" placeholder="节点名称">
    </div>
    <div class="form-row">
        <label for="node-input-algorithm"><i class="icon-tag"></i>加密方式</label>
        <select type="text" id="node-input-algorithm" style="width:70%;">
            <option value="HmacMD5">MD5</option>
            <option value="HmacRIPEMD160">RIPEMD160</option>
            <option value="HmacSHA1">SHA1</option>
            <option value="HmacSHA3">SHA3</option>
            <option value="HmacSHA224">SHA224</option>
            <option value="HmacSHA256">SHA256</option>
            <option value="HmacSHA384">SHA384</option>
            <option value="HmacSHA512">SHA512</option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-key"> 加密秘钥</label>
        <input type="text" id="node-input-key" placeholder="加密秘钥"">
        <input type="hidden" id="node-input-fieldTypeToHash">
    </div> 
</script>

<script type="text/x-red" data-help-name="hmac">
    <p>Create a keyed-hash message (HMAC) of payload using the specified algorithm.</p>
</script>